home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Procedure: addTextureToShaderLayered
- //
- // Description:
- //
- // Add a file texture to a shader node's color connection
- // with either adding a new layered texture in between,
- // or adding a new layer to an existing layered texture
- // connection
- //
- // Arguments:
- // shader : shader / shading engine to add to
- // thisTexture : texture to add
- // killColorLayer : replace color layer in layered texture
- // connectAlpha : connect alpha of texture to layered texture alpha
- //
- // Author : Bernard Kwok
- // Last Updated : 07/18/00
- //
- proc string plugNode( string $plug )
- {
- string $buffer[];
- tokenize($plug, ".", $buffer);
- return $buffer[0];
- }
-
- global proc addTextureToShaderLayered(string $shader,
- string $thisTexture,
- int $blendMode,
- int $killColorLayer,
- int $connectAlpha)
- {
- //if (size($shader) == 0)
- // error ("No shader name passed to addTextureToShaderLayered()");
- //if (size($thisTexture) == 0);
- // error ("No texture name passed to addTextureToShaderLayered()");
-
- // Check to see if we got passed in a shading engine
- string $shaderAttr = ".color";
- string $sType[] = `ls -showType $shader`;
- if ($sType[1] == "shadingEngine")
- {
- string $shaders[] = `listConnections -d 1 ($shader+".surfaceShader")`;
- $shader = $shaders[0];
- if (size($shader) == 0)
- $shaderAttr = ".surfaceShader";
- }
-
- // Check if the shader already has a layered texture
- // if so use it.
- string $colorCons[] = `listConnections -d on -p on ($shader+$shaderAttr)`;
-
- string $layeredTx = "";
- string $existingTx = "";
- if (size($colorCons))
- {
- string $node = `plugNode $colorCons[0]`;
- string $nType[] = `ls -showType $node`;
- if ($nType[1] == "layeredTexture")
- {
- $layeredTx = $nType[0];
- }
- // See if its any kind of texture
- else
- {
- string $allTex[] = `ls -tex`;
- for ($i = 0; $i < size($allTex); $i++)
- {
- if ($node == $allTex[$i])
- {
- $existingTx = $node;
- break;
- }
- }
- }
- }
-
- // Break old non-layered texture connection
- if (size($layeredTx) == 0)
- {
- if (size($colorCons))
- {
- disconnectAttr ($colorCons[0]) ($shader+$shaderAttr);
-
- // If there was an existing texture than hook that up
- // to the layered texture first.
- if (size($existingTx))
- {
- $layeredTx = addToLayeredTx( $layeredTx, $existingTx, $blendMode, 0, 0);
- //print ("Add existing to layered tex " + $layeredTx + "\n");
- }
- }
-
- // Hook the file texture to the layered texture.
- $layeredTx = addToLayeredTx( $layeredTx, $thisTexture, $blendMode, $killColorLayer, $connectAlpha );
-
- // Hook the layered texture up to the shader
- connectAttr ($layeredTx+".outColor") ($shader+$shaderAttr);
- }
- else
- {
- // If there was an existing texture than hook that up
- // to the layered texture first.
-
- // Just hook up the file texture to the existin layered texture
- addToLayeredTx( $layeredTx, $thisTexture, $blendMode, $killColorLayer, $connectAlpha );
- }
- }
-
-